<template>
  <div class="mod-info">
    <!-- <el-row> -->
    <!-- <el-col :span="6"> -->
    <div class="grid-content bg-purple-dark">
      <el-form
        ref="form"
        :model="form"
        label-width="150px"
        class="demo-ruleForm"
      >
        <div class="title">运费组合策略</div>
        <el-form-item label="">
          <el-radio v-model="form.freight_strategy" :label="0">
            叠加 订单总运费为各个商品运费之和</el-radio
          >
          <el-radio v-model="form.freight_strategy" :label="1"
            >最高运费 订单总运费为运费最高商品运费</el-radio
          >
          <el-radio v-model="form.freight_strategy" :label="2"
            >最低运费 订单总运费为运费最低的商品运费</el-radio
          >
        </el-form-item>
        <template v-if="false">
          <div>
            <div class="title">到店自提设置</div>
            <el-form-item label="是否开启自提" prop="name">
              <el-switch
                v-model="form.able_pickup"
                active-color="#13ce66"
                inactive-color="#cccccc"
              >
              </el-switch>
            </el-form-item>
            <el-form-item
              label="系统自动备货"
              prop="name"
              v-if="form.able_pickup"
            >
              <el-switch
                v-model="form.auto_stock"
                active-color="#13ce66"
                inactive-color="#cccccc"
              >
              </el-switch>
              <span>开启后可自动备货，无需手动点击备货</span>
            </el-form-item>
            <el-form-item
              label="订单支付后"
              v-if="form.able_pickup == true && form.auto_stock == true"
              :rules="[{ required: true, message: '关键词不能为空' }]"
            >
              <el-row>
                <el-col :span="8">
                  <el-input-number
                    style="width:150px"
                    v-model="form.delay_days"
                    :min="0"
                    :max="30"
                  ></el-input-number>
                  <span>天(0-30)</span>
                </el-col>
                <el-col :span="8">
                  <el-input-number
                    style="width:150px"
                    v-model="form.delay_hours"
                    :min="0"
                    :max="23"
                  ></el-input-number>
                  <span>小时(0-23)</span>
                </el-col>
                <el-col :span="8">
                  <el-input-number
                    style="width:150px"
                    v-model="form.delay_minutes"
                    :min="10"
                    :max="59"
                  ></el-input-number>
                  <span>分钟(10-59)</span>
                </el-col>
              </el-row>
            </el-form-item>

            <el-form-item
              label="提货有效期"
              v-if="form.able_pickup == true"
              prop="name"
            >
              <el-switch
                v-model="form.able_pickup_expired"
                active-color="#13ce66"
                inactive-color="#cccccc"
              >
              </el-switch>
              <span>关闭提货有效期，用户不自提，订单一直处于待提货状态</span>
            </el-form-item>
            <div
              v-if="
                form.able_pickup_expired == true && form.able_pickup == true
              "
            >
              <el-form-item label="备货完成">
                <el-row>
                  <el-col :span="24">
                    <el-input-number
                      v-model="form.pickup_expired"
                      :min="1"
                      :max="30"
                    ></el-input-number>
                    <span>天后停止提货(1-30)</span>
                  </el-col>
                </el-row>
              </el-form-item>
              <el-form-item label="过期订单处理">
                <el-radio v-model="form.expired_order_handle_type" :label="0">
                  过期后，订单自动完成，不退款</el-radio
                >
                <!-- <el-radio v-model="form.expired_order_handle_type" :label="1">过期后，订单自动售后，退款</el-radio> -->
              </el-form-item>
            </div>
          </div>
        </template>
        <el-form-item>
          <el-button type="primary" @click="onSubmit('form')">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import seviceApi from '@/api/serviceApi.js'
export default {
  data() {
    return {
      form: {
        able_pickup: false, // 是否开通自提
        able_pickup_expired: false, // 开启提货有效期
        pickup_expired: 1, // 提货过期的天数（1-30天）
        expired_order_handle_type: 0, // 自提过期订单处理类型
        delay_days: 0,
        delay_hours: 0,
        delay_minutes: 10,
        auto_stock: false, // 是否开启系统自动备货
        freight_strategy: 0 // 运费计算策略
      }
    }
  },
  mounted() {
    this.getInfo()
  },
  methods: {
    getInfo() {
      seviceApi.getLogisticsconfigInfo().then(res => {
        if (res && res.data.code == 200) {
          if (res.data.data) {
            this.form = res.data.data
          }
        }
      })
    },
    onSubmit(form) {
      this.$refs[form].validate(valid => {
        if (valid) {
          this.form.able_pickup = false
          seviceApi.saveLogisticsconfig(this.form).then(res => {
            if (res && res.data.code == 200) {
              this.$message({
                message: '保存成功',
                type: 'success'
              })
              this.getInfo()
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    handlePreview(file) {
      console.log(file)
    }
  }
}
</script>

<style>
.title {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #cccccc;
  margin-bottom: 30px;
}

.text-center {
  text-align: center;
}
</style>
